<?php

namespace App\Requests;

use App\Exceptions\ExceptionSms;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;

/**
 * @author: zlz
 * @datetime: 2020-06-09 19:05
 * Class BaseRequest
 * @package App\Requests
 */
class BaseRequest extends FormRequest
{
    /**
     * @name: authorize
     * @return bool
     * @author: zlz
     * @datetime: 2020-06-09 19:05
     */
    public function authorize()
    {
        return true;
    }

    /**
     * @name: failedValidation
     * @param Validator $validator
     * @author: zlz
     * @datetime: 2020-06-09 19:05
     */
    protected function failedValidation(Validator $validator)
    {
        $error = $validator->errors()->all();

        ExceptionSms::returnError($error[0]);
    }

    public function isUpdate()
    {
        if (stripos($this->getPathInfo(), '/update') !== false) {
            return true;
        } else {
            return false;
        }
    }
}
